package com.tencent.cloud.iov.util;

import android.graphics.PointF;
import android.view.MotionEvent;

/**
 * @author vinsonhuang
 * @date 2018/9/28
 */
public class MotionEventUtils {

    /**
     * 动作标志：无
     */
    public static final int NONE = 0;

    /**
     * 动作标志：拖动
     */
    public static final int DRAG = 1;

    /**
     * 动作标志：缩放
     */
    public static final int ZOOM = 2;

    /**
     * 多点触控时，计算最先放下的两指距离
     *
     * @param event
     * @return
     */
    public static float spacing(MotionEvent event) {
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return (float) Math.sqrt(x * x + y * y);
    }

    /**
     * 多点触控时，计算最先放下的两指中心坐标
     *
     * @param point
     * @param event
     */
    public static void midPoint(PointF point, MotionEvent event) {
        float x = event.getX(0) + event.getX(1);
        float y = event.getY(0) + event.getY(1);
        point.set(x / 2, y / 2);
    }
}
